home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte18 / ex2.c < prev    next >
C/C++ Source or Header  |  1994-12-26  |  3KB  |  98 lines

  1. #include <genstub.c>
  2.  
  3. void NameClipFormat( UINT uFormat, char *cName );
  4.  
  5. LRESULT CALLBACK WndProc( HWND  hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  6. {
  7.    switch (uMsg)         /* process windows messages */
  8.    {
  9.        case WM_COMMAND:         /* process menu items */
  10.                switch (LOWORD(wParam))
  11.                {
  12.                   case IDM_TEST:  
  13.                   {    // User hit the "Test" menu item 
  14.                      int  i;
  15.                      int  nCBFormats;
  16.                      HDC hDC = GetDC( hWnd );
  17.                      nCBFormats = CountClipboardFormats( );
  18.                      OpenClipboard( hWnd );
  19.                      for (i = 0 ; i < nCBFormats ; i++)
  20.                      {
  21.                         char cBuf [128];
  22.                         char cName [64];
  23.                         UINT uFormat = EnumClipboardFormats( uFormat );
  24.                         // We know we have a valid format because we used
  25.                         // CountClipboardFormats to return number of formats.
  26.                         NameClipFormat( uFormat, cName );
  27.                         TextOut( hDC, 10, i * 20, cBuf, 
  28.                         wsprintf( cBuf, "%s, ( 0x%x ) clipboard format available.", 
  29.                               (LPSTR) cName, uFormat) );
  30.                      }
  31.                      CloseClipboard( );
  32.                      ReleaseDC( hWnd, hDC );
  33.                      break ;
  34.                   }
  35.                   case IDM_EXIT:      
  36.                      DestroyWindow( hWnd );
  37.                   break;
  38. #include <aboutopt.c>
  39.  
  40.                }
  41.                break;
  42.        case WM_DESTROY:      
  43.                PostQuitMessage( 0 );
  44.        break ;
  45.  
  46.             // right button mouse interface
  47.  
  48. #include <rbutton.c>
  49.  
  50.        default:
  51.                return DefWindowProc( hWnd, uMsg, wParam, lParam );
  52.    }
  53.    return (0L) ;
  54. }
  55.  
  56. /* fills in cName with name of a clipboard format */
  57.  
  58. #ifdef WINDOWS95
  59.     #define PREDEFINED_CLIPBOARD_FORMAT_COUNT  17
  60. #else
  61.     #define PREDEFINED_CLIPBOARD_FORMAT_COUNT  14
  62. #endif
  63.  
  64. void NameClipFormat (UINT uFormat, char *cName)
  65. {
  66.    static char *cClipName [PREDEFINED_CLIPBOARD_FORMAT_COUNT + 1] = 
  67.                     {"CF_FIRST", "CF_TEXT", "CF_BITMAP", 
  68.                      "CF_METAFILEPICT", "CF_SYLK", "CF_DIF", "CF_TIFF", 
  69.                      "CF_OEMTEXT", "CF_DIB", "CF_PALETTE" , "CF_PENDATA", "CF_RIFF",
  70.                      "CF_WAVE", "CF_UNICODETEXT", "CF_ENHMETAFILE"
  71. #ifdef WINDOWS95
  72.                    , "HDROP", "LOCALE", "MAX"   // not available in NT or Win32s
  73. #endif
  74.    };
  75.  
  76.    static char *cClipName2 [4] = 
  77.     {"CF_OWNERDISPLAY", "CF_DSPTEXT", "CF_DSPBITMAP", "CF_DSPMETAFILEPICT"};
  78.    
  79.    int nLengthFormatName = GetClipboardFormatName( uFormat,  cName, 63 );
  80.  
  81.    if (nLengthFormatName == 0) {
  82.       /* predefined format */
  83.       if (uFormat <= PREDEFINED_CLIPBOARD_FORMAT_COUNT)
  84.          lstrcpy( cName, cClipName[uFormat - CF_FIRST] );
  85.       else if ((uFormat <= CF_DSPMETAFILEPICT) && (uFormat >= CF_OWNERDISPLAY))
  86.          lstrcpy( cName, cClipName2[uFormat - CF_OWNERDISPLAY] );
  87.       else if (uFormat==0x8e)
  88.          lstrcpy( cName, "CF_DSPENHMETAFILE" );
  89.       else if (uFormat>=0x300 && uFormat<=0x3ff)
  90.          wsprintf( cName, "CF_GDIOBJFIRST+%d", uFormat-CF_GDIOBJFIRST );
  91.       else
  92.          strcpy( cName, "<Not named>" );
  93.    }
  94.  
  95. }
  96.  
  97. #include <about.c>
  98.